package com.qire.manhua.activity.intercept;

import android.content.Context;

import com.qire.antscore.annotation.InterceptorMapping;
import com.qire.antsrouter.card.Postcard;
import com.qire.antsrouter.intercept.InterceptRules;
import com.qire.antsrouter.intercept.Interceptor;
import com.qire.common.collect.ArrayUtil;
import com.qire.common.constant.Navigation;
import com.qire.common.constant.TeensModeManage;
import com.qire.common.utils.ToastHelper;

/**
 * 青少年模式拦截器
 */
@InterceptorMapping
public class TeensModeIntercept implements InterceptRules {

    /** 白名单 */
    private String[] whitelist = {
            Navigation.Page.MainPage,
            Navigation.Page.TeensLockSleepPage,
            Navigation.Page.TeensLockTimeoutPage,
            Navigation.Page.TeensControlPanelPage,
            Navigation.Page.TeensModeTogglePage,
            Navigation.Page.TeensModifyPasswordPage,
            Navigation.Page.TeensRetrievePasswordPage
    };

    @Override
    public void init(Context context) { }

    @Override
    public void process(Postcard postcard, Interceptor interceptor) {
        boolean isNotInWhiteList = ArrayUtil.indexOf(whitelist, postcard.getPath()) < 0;
        if(isNotInWhiteList && TeensModeManage.gotoPageInterrupt()) {
            interceptor.onInterrupt(String.format("TeensMode interceptor 青少年模式锁定，拦截了跳转%s的页面", postcard.getPath()));
            ToastHelper.showCenterDarkToast("", "青少年模式：已进入非阅读时间");
            return;
        }
        interceptor.onNext();
    }

}
